const mockScoreList = [
  {
    id: 1,
    studentName: "Cy Ganderton",
    class: "Class 1 | Year 9",
    subject: "Math.",
    semester: "2025 Autumn",
    score: 95,
  },
  {
    id: 2,
    studentName: "Lila Mckenzie",
    class: "Class 1 | Year 9",
    subject: "Math.",
    semester: "2025 Autumn",
    score: 88,
  },
  {
    id: 3,
    studentName: "Jake Thompson",
    class: "Class 2 | Year 9",
    subject: "Math.",
    semester: "2025 Autumn",
    score: 92,
  },
  {
    id: 4,
    studentName: "Emma Wilson",
    class: "Class 1 | Year 9",
    subject: "English",
    semester: "2025 Autumn",
    score: 90,
  },
  {
    id: 5,
    studentName: "Noah Brown",
    class: "Class 3 | Year 9",
    subject: "Math.",
    semester: "2025 Autumn",
    score: 85,
  },
  {
    id: 6,
    studentName: "Olivia Davis",
    class: "Class 1 | Year 9",
    subject: "Science",
    semester: "2025 Autumn",
    score: 94,
  },
  {
    id: 7,
    studentName: "Ethan Garcia",
    class: "Class 2 | Year 9",
    subject: "Math.",
    semester: "2025 Autumn",
    score: 79,
  },
  {
    id: 8,
    studentName: "Ava Martinez",
    class: "Class 3 | Year 9",
    subject: "English",
    semester: "2025 Autumn",
    score: 86,
  },
  {
    id: 9,
    studentName: "Lucas Rodriguez",
    class: "Class 1 | Year 9",
    subject: "Science",
    semester: "2025 Autumn",
    score: 91,
  },
  {
    id: 10,
    studentName: "Mia Anderson",
    class: "Class 2 | Year 9",
    subject: "Math.",
    semester: "2025 Autumn",
    score: 83,
  },
  {
    id: 11,
    studentName: "Elijah Taylor",
    class: "Class 3 | Year 9",
    subject: "Science",
    semester: "2025 Autumn",
    score: 89,
  },
  {
    id: 12,
    studentName: "Sophia Thomas",
    class: "Class 1 | Year 9",
    subject: "English",
    semester: "2025 Autumn",
    score: 93,
  },
  {
    id: 13,
    studentName: "Liam Hernandez",
    class: "Class 2 | Year 9",
    subject: "Science",
    semester: "2025 Autumn",
    score: 77,
  },
  {
    id: 14,
    studentName: "Amelia Moore",
    class: "Class 3 | Year 9",
    subject: "Math.",
    semester: "2025 Autumn",
    score: 81,
  },
  {
    id: 15,
    studentName: "Noah Martin",
    class: "Class 1 | Year 9",
    subject: "Math.",
    semester: "2025 Autumn",
    score: 87,
  },
  {
    id: 16,
    studentName: "Harper Jackson",
    class: "Class 2 | Year 9",
    subject: "English",
    semester: "2025 Autumn",
    score: 96,
  },
  {
    id: 17,
    studentName: "Mason White",
    class: "Class 3 | Year 9",
    subject: "Science",
    semester: "2025 Autumn",
    score: 75,
  },
  {
    id: 18,
    studentName: "Evelyn Harris",
    class: "Class 1 | Year 9",
    subject: "Math.",
    semester: "2025 Autumn",
    score: 84,
  },
  {
    id: 19,
    studentName: "Logan Clark",
    class: "Class 2 | Year 9",
    subject: "Science",
    semester: "2025 Autumn",
    score: 97,
  },
  {
    id: 20,
    studentName: "Abigail Lewis",
    class: "Class 3 | Year 9",
    subject: "English",
    semester: "2025 Autumn",
    score: 82,
  },
];

import { supabase } from "@/ultils/supabase.js";

export async function getScoreList() {
  const { data: score, error } = await supabase.from("score").select("*");

  if (error) {
    console.log(error.message);
    return;
  }

  return score;
}

export async function createScore(newScore) {
  const { data, error } = await supabase
    .from("score")
    .insert([newScore])
    .select();
  if (error) {
    console.log(error.message);
    return;
  }
  return data;
}

// 2. 定义通过ID查询数据的函数
export async function getScoreById(id) {
  const { data: score, error } = await supabase
    .from("score")
    .select("*")
    .eq("id", id);

  if (error) {
    console.log(error.message);
    return;
  }

  return score;
}

export async function updateScore(scoreId, newScore) {
  const { data, error } = await supabase
    .from("score")
    .update(newScore)
    .eq("id", scoreId)
    .select();

  if (error) {
    console.log(error.message);
    return;
  }
  return data;
}
